layui.use(['form','jquery','table','layer'],function() {
    var form = layui.form
        , $ = layui.jquery
        , table = layui.table
        , layer = layui.layer;


    //检索
    search = function search(){
        var courseName = $('input[name=courseName]').val();
        var name = $('select[name=name]').val();
        var trueName = $('select[name=trueName]').val();
        var courseCstatus = $('select[name=courseCstatus]').val();
        if(courseCstatus == ''){
            courseCstatus = '';
        }else if(courseCstatus == '未审核'){
            courseCstatus = 3;
        }else if(courseCstatus == '审核中'){
            courseCstatus = 4;
        }else if(courseCstatus == '审核失败'){
            courseCstatus = 5;
        }else if(courseCstatus == '其他'){
            courseCstatus = 6;
        }
        $.ajax({
             url: '/course/journalRetrieval'
            ,data: {
                 'courseName': courseName
                ,'name': name
                ,'trueName': trueName
                ,'courseCstatus': courseCstatus
            }
            ,dataType: 'json'
            ,success:function(data){
                tableRender(data.data);
            }
        });
    }


    //重置检索内容
    reset = function reset(){
        $('input[name=courseName]').val('');
        $('select[name=name]').val('');
        $('select[name=trueName]').val('');
        $('select[name=courseCstatus]').val('');
    }


    //请求表格数据
    $.ajax({
        url: '/course/getCourseJournals'
        ,dataType: 'json'
        ,success:function (data) {
            tableRender(data.data);
        }
    });


    //渲染表格函数
    function tableRender(data){
        table.render({
            elem: '#myTable'
            ,data: data
            ,page: true
            ,cols: [[
                {field: 'id',title: '课程编号',align: 'center'}
                ,{field: 'courseName',title: '课程名称',align: 'center'}
                ,{field: 'cssClass',title: '课程现价',align: 'center'}
                ,{field: 'listClass',title: '课程原价',align: 'center'}
                ,{field: 'courseStatus',title: '商品状态',align: 'center',templet:function (data) {
                        if(data.courseStatus == '2'){
                            return '已上架'
                        }else if(data.courseStatus == '3'){
                            return '下架×'
                        }else{
                            return '数据错误';
                        }
                    }}
                ,{field: 'courseCstatus',title: '审核状态',align: 'center',templet:function (data) {
                        if(data.courseCstatus == '3'){
                            return '未审核'
                        }else if(data.courseCstatus == '4'){
                            return '审核中'
                        }else if(data.courseCstatus == '5'){
                            return '审核失败'
                        }else if(data.courseCstatus == '6'){
                            return '其他'
                        }else{
                            return '数据错误';
                        }
                    }}
                ,{field: 'updateBy',title: '操作人员',align: 'center'}
                ,{field: 'updateTime',title: '操作时间',align: 'center'}
            ]]
        });
    }
    //返回
    backOff = function backOff() {
        var arr = localStorage.getItem("numArr");
        var numArr = arr.split(",");
        numArr.pop();
        window.parent.layui.element.tabChange('tab',numArr[numArr.length - 1]);
        localStorage.setItem("numArr",numArr);
    }
    //刷新
    refresh = function refresh(){
        window.location.reload();
    }





});